package br.com.controller;

import java.sql.Connection;

import javax.servlet.http.HttpSession;


import br.com.dao.LoginDao;
import br.com.bean.LoginBean;

public class LoginControle {
	/*public static void inserir(Connection conn, PerfilBean perfil, String senha, String email) throws Exception {
		LoginBean loginBean = new LoginBean();
		loginBean.setPerfil(perfil);
		loginBean.setSenha(senha);
		loginBean.setEmail(email);
		LoginDAO dao = new LoginDAO();
		dao.addLogin(conn, loginBean);

	}

	public static void remover(Connection conn, int id) throws Exception {
		LoginBean loginBean = new LoginBean();
		loginBean.setId(id);
		LoginDAO dao = new LoginDAO();
		dao.removerLogin(conn, loginBean);
	}

	public static void update(Connection conn, int codPerfilLog, String senha) throws Exception {
		LoginBean loginBean = new LoginBean();
		loginBean.getPerfil().setId(codPerfilLog);
		loginBean.setSenha(senha);
		LoginDAO dao = new LoginDAO();
		dao.alterarLogin(conn, loginBean);
	}
	
	public static int getLoginCod(Connection conn, int codPerfilLogado) throws Exception {
		LoginDAO dao = new LoginDAO();
		int getLogin = dao.getLoginCod(conn, codPerfilLogado);
		return getLogin;

	}

	public static LoginBean getLogin(Connection conn, int codPerfilLogado) throws Exception {
		LoginDAO dao = new LoginDAO();
		LoginBean getLogin = dao.getLogin(conn, codPerfilLogado);
		return getLogin;

	}
	public static boolean validaLogin(Connection conn, String email, String senha) throws Exception {
		LoginDAO dao = new LoginDAO();
		return dao.validaLogin(conn, email, senha);

	}*/
	public static boolean verificaSenha(Connection conn, String usuario, String senha) throws Exception {
		LoginBean login = new LoginBean();
		login.setSenha(senha);
		login.setUsuario(usuario);
		LoginDao dao = new LoginDao();
		if(dao.validaLogin(conn, login)){
			return true;
		}else{
			return false; 
		}
	}
	public static String logout(HttpSession session) {
		session.invalidate();
		return "redirect:SistemaFinanceiro/index";
	}
}
